package com.bawei.java.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

/**
 * @Author : yaotianxue
 * @Time : On 2023/5/24 13:47
 * @Description : Test 自定义注解+通过反射获得注解信息
 */
public class Test {
    public static void main(String[] args) throws NoSuchFieldException {
        //反射获得student类上的注解属性
        Class class1 = Student.class;
        //获得类上的注解
        MyTable myTable = (MyTable) class1.getAnnotation(MyTable.class);
        String name = myTable.name();//获得注解里的name属性
        System.out.println("类上的注解:"+name);
        //获得Student类变量上的注解
        Field name1 = class1.getDeclaredField("name");
        MyTable myTable1 = name1.getAnnotation(MyTable.class);
        System.out.println("变量上的的注解:"+myTable1.name());
    }
}
